﻿/* 6. Write a program that, for a given two integer numbers N and X, 
 * calculates the sumS = 1 + 1!/X + 2!/X^2 + … + N!/X^N. */

using System;

public class SpecialSum
{
    public static void Main()
    {
        int n;
        int x;
        int numerator;
        int denominator;
        decimal sum = 1M;

        do
        {
            Console.Clear();
            Console.Write("N = ");
            if (int.TryParse(Console.ReadLine(), out n))
            {
                Console.Clear();
                Console.WriteLine("N = {0}", n);
                Console.Write("X = ");
                if (int.TryParse(Console.ReadLine(), out x))
                    break;
            }
        } while (true);

        for (int i = 1; i <= n; i++)
        {
            numerator = 1;
            denominator = 1;
            for (int j = i; j > 0; j--)
            {
                numerator *= j;
                denominator *= x;
            }

            sum += (1.0M * numerator) / denominator;
        }

        Console.WriteLine("S = 1 + 1!/X + 2!/X*X + ... + N!/Pow(X, N) = {0}", sum);
    }
}